import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  DeviceOrientation _currentOrientation = DeviceOrientation.portraitUp;

  void _incrementCounter() {
    setState(() {
      if (_currentOrientation == DeviceOrientation.portraitUp) {
        _currentOrientation = DeviceOrientation.landscapeLeft;
      } else {
        _currentOrientation = DeviceOrientation.portraitUp;
      }
      SystemChrome.setPreferredOrientations([_currentOrientation]);
    });
  }

  Future<bool?> showDeleteConfirmDialog() {
    return showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text('标题'),
          content: const Text('这是一个对话框内容。'),
          actions: <Widget>[
            TextButton(
              child: const Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

  createViewItem(len, w, h) {
    List<Widget> list = [];
    for (var i = 0; i < len; i++) {
      list.add(Container(width: w, height: h, color: Colors.green));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter app'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            ElevatedButton(
                onPressed: () {
                  showModalBottomSheet(
                    context: context,
                    builder: (BuildContext context) {
                      return Container(
                        height: 1000,
                        child: TextField(),
                      );
                    },
                  );
                },
                child: Text('打开底部弹窗')),
            ElevatedButton(
                onPressed: () async {
                  await showDeleteConfirmDialog();
                },
                child: Text('对话框'))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
